<template>
  <div class="app-container">
    <div v-show="active === 1">
      <div class="searchform">
        <!-- 查询条件 -->
        <el-form ref="searchForm" :model="search" size="mini" label-width="90px">
          <!--          <el-form-item prop="orgName" label="部门名称">-->
          <!--            <el-input v-model="search.orgName" placeholder="部门名称" />-->
          <!--          </el-form-item>-->
          <el-row :gutter="6">
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="employeeName" label="员工姓名">
                <el-input v-model="search.employeeName" placeholder="员工姓名" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="employeeNo" label="员工编号">
                <el-input v-model="search.employeeNo" placeholder="员工编号" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="userCode" label="用户帐号">
                <el-input v-model="search.userCode" placeholder="员工帐号" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="phone" label="手机">
                <el-input v-model="search.phone" placeholder="手机" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="isOnjob" label="在职状态">
                <el-select v-model="search.isOnjob" :clearable="true" placeholder="请选择">
                  <el-option v-for="item in isOnjob" :key="item.code" :label="item.name" :value="item.code">{{ item.name }}</el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <!-- 用户_职位 -->
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="departmentName" label="部门">
                <el-input v-model="search.departmentName" placeholder="部门" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="positionName" label="职位">
                <el-input v-model="search.positionName" placeholder="职位" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="roleName" label="角色">
                <el-input v-model="search.roleName" placeholder="角色" clearable/>
              </el-form-item>
            </el-col>

            <div style="text-align:right">
              <el-button type="primary" icon="el-icon-search" @click="searchHandle">查询
              </el-button>
              <el-button icon="el-icon-refresh" @click="resetForm('searchForm')">重置
              </el-button>
            </div>
          </el-row>
        </el-form>
      </div>
      <!-- 用户列表 -->
      <div class="table">
        <div class="tableHead">
          <div class="tabletitle">员工信息</div>
          <div class="btnGroup">
            <el-button-group>
              <el-button icon="el-icon-plus" type="primary" @click="add">新增用户</el-button>
              <el-button type="primary" icon="el-icon-refresh" @click="restClick" >重置密码</el-button>
              <!-- <el-button type="primary" icon="el-icon-download" @click="exportData">导出</el-button> -->
            </el-button-group>
          </div>
        </div>
        <baseTable ref="table" @chaneg-size="changeSizeHandle" @chaneg-page="changePageHandle" @selection-change="handleSelectionChange2">
          <el-table-column type="index" label="序号" min-width="50"/>
          <el-table-column type="selection" width="50"/>
          <el-table-column align="center" label="操作" min-width="180">
            <template slot-scope="scope">
              <el-tooltip class="item" content="编辑" placement="bottom" >
                <el-button :disabled="scope.row.IS_ONJOB === '10081002'" type="text" style="font-size: 20px;" icon="el-icon-edit-outline" @click="edit(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="明细" placement="bottom">
                <el-button type="text" style="font-size: 20px;" icon="el-icon-document" @click="detail(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="解锁" placement="bottom">
                <el-button
                  :disabled="scope.row.LOCK_FLAG === 10041002 || scope.row.IS_ONJOB === '10081002'"
                  type="text"
                  style="font-size: 20px;"
                  icon="el-icon-sold-out"
                  @click="removelock(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="锁定" placement="bottom">
                <el-button :disabled="scope.row.LOCK_FLAG === 10041001 || scope.row.IS_ONJOB === '10081002'" type="text" style="font-size: 20px;" icon="el-icon-goods" @click="lock(scope.row)"/>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column prop="USER_CODE" label="员工账号" min-width="150"/>
          <el-table-column prop="EMPLOYEE_NO" label="员工编号" min-width="150"/>
          <el-table-column prop="EMPLOYEE_NAME" label="员工姓名" min-width="100">
            <template slot-scope="scope">
              <a style="color:#4587ff;" @click="handelRole({name:'AuthorizationManagement',params: {employeeName: scope.row.EMPLOYEE_NAME}})">{{ scope.row.EMPLOYEE_NAME }}</a>
            </template>
          </el-table-column>

          <el-table-column :show-overflow-tooltip="true" prop="ORGANIZATION_NAME" label="部门" min-width="150"/>
          <!--          <el-table-column prop="AREA_NAME" label="业务范围" min-width="150"/>-->
          <el-table-column :show-overflow-tooltip="true" prop="POSITION_NAME" label="职位" min-width="150">
            <template slot-scope="scope">
              <a style="color:#4587ff;" @click="handelRole({name:'GmsPositionAuth',params: {positionName: scope.row.POSITION_NAME}})">{{ scope.row.POSITION_NAME }}</a>
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="ROLE_NAME" label="角色" min-width="150">
            <template slot-scope="scope">
              <a style="color:#4587ff;" @click="handelRole({name:'Gmsrolemmanage',params: {roleName: scope.row.ROLE_NAME}})">{{ scope.row.ROLE_NAME }}</a>
            </template>
          </el-table-column>
          <!--<el-table-column prop="EDUCATION" label="学历" type="9015" :formatter="filterCode" min-width="100">-->
          <!--</el-table-column>-->
          <el-table-column :formatter="filterCode" prop="GENDER" label="性别" min-width="50" type="1002">
            <!--<template slot-scope="scope">
              <span>{{ scope.row.GENDER | genderFilter }}
              </span>
            </template>-->
          </el-table-column>
          <el-table-column prop="CERTIFICATE_ID" label="身份证号" min-width="150"/>
          <el-table-column prop="MOBILE" label="手机" min-width="120"/>
          <el-table-column prop="LOCK_FLAG" label="是否锁定" min-width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.LOCK_FLAG === 10041001 ? 'success' : 'primary'" close-transition>{{ scope.row.LOCK_FLAG
              | isYESORNO }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="IS_ONJOB" label="在职状态" min-width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.IS_ONJOB === 10081001 ? 'success' : 'primary'">{{ scope.row.IS_ONJOB |
              isonjobFilter }}
              </el-tag>
            </template>
          </el-table-column>
        </BaseTable>
      </div>
    </div>
    <!-- 弹框 -->
    <el-dialog :title="text" :visible.sync="dialogFormVisible" :close-on-click-modal="false" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :disabled="!bols" label-width="90px">
        <div class="searchform">
          <el-row :gutter="6">
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item label="员工编号" prop="EMPLOYEE_NO">
                <el-input v-model="form.EMPLOYEE_NO" :disabled="bol" placeholder="员工编号" >
                  <!--                <template slot="prepend" v-if="!bol">{{dealercode}}</template>-->
                </el-input>
                <el-input v-show="false" v-model="form.EMPLOYEE_ID" placeholder="员工id" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item label="员工姓名" prop="EMPLOYEE_NAME">
                <el-input v-model="form.EMPLOYEE_NAME" :disabled="way == 'detail'" placeholder="员工姓名" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item v-if="false" prop="POSITION_CODE">
                <el-input v-model="form.POSITION_CODE" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item label="性别" prop="GENDER">
                <r-select v-model="form.GENDER" type="1002" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item label="出生日期" prop="BIRTHDAY">
                <el-date-picker v-model="form.BIRTHDAY" type="date" placeholder="出生日期"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item label="身份证号" prop="CERTIFICATE_ID">
                <el-input v-model="form.CERTIFICATE_ID" placeholder="身份证号" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item label="手机" prop="PHONE">
                <el-input v-model="form.PHONE" placeholder="手机" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item label="E_MAIL" prop="E_MAIL">
                <el-input v-model="form.E_MAIL" placeholder="E_MAIL" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item label="邮编" prop="ZIP_CODE">
                <el-input v-model="form.ZIP_CODE" placeholder="邮编" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item prop="IS_ONJOB" label="在职状态">
                <el-select v-model="form.IS_ONJOB" placeholder="请选择" @change="isOnjobChange">
                  <el-option v-for="item in isOnjob" :key="item.code" :label="item.name" :value="item.code">{{ item.name }}</el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item label="离职日期" prop="DIMISSION_DATE">
                <el-date-picker v-model="form.DIMISSION_DATE" :disabled="true" type="date" placeholder="离职日期"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item label="建档日期" prop="FOUND_DATE" type="date">
                <el-date-picker v-model="form.FOUND_DATE" :disabled="true" type="date" placeholder="建档日期" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">

              <!--<el-form-item label="产品大类" prop="BIG_RANGE">-->
              <!--<r-select v-model="form.BIG_RANGE" :multiple="true" type="8057" placeholder="请选择" ></r-select>-->
              <!--</el-form-item>-->
              <el-form-item label="地址" prop="ADDRESS">
                <el-input v-model="form.ADDRESS" placeholder="地址" width="30%" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button v-show="bols" type="primary" @click="save">保 存</el-button>
        <el-button @click="cancel()">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 代理商选择div -->
    <el-dialog :visible.sync="dialogVisible" title="代理商选择" width="70%">
      <div class="searchform">
        <!-- 查询条件 -->
        <el-form ref="searchDealerForm" :inline="true" :model="dealerSearch" size="mini" label-width="90px">
          <el-form-item prop="dealerCode" label="代理商代码">
            <el-input v-model="dealerSearch.dealerCode" placeholder="代理商代码" clearable />
          </el-form-item>
          <el-form-item prop="dealerName" label="代理商名称">
            <el-input v-model="dealerSearch.dealerName" placeholder="代理商名称" clearable />
          </el-form-item>
          <div style="text-align:center">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="searchDealer">查询
              </el-button>
            </el-form-item>
            <el-form-item>
              <el-button icon="el-icon-refresh" @click="resetForm('searchDealerForm')">重置
              </el-button>
            </el-form-item>
          </div>
        </el-form>
      </div>
      <!-- 代理商列表 -->
      <div class="table">
        <div class="tableHead">
          <div class="tabletitle">代理商信息</div>
        </div>
        <el-table
          v-loading="load"
          ref="dealerTable"
          :data="list"
          tooltip-effect="dark"
          style="width: 100%"
          stripe
          border
          @selection-change="handleSelectionChange">
          <el-table-column type="index" label="序号" width="50"/>
          <el-table-column type="selection" width="40"/>
          <el-table-column prop="DEALER_CODE" label="代理商代码" min-width="50"/>
          <el-table-column prop="DEALER_NAME" label="代理商名称" min-width="50"/>
          <el-table-column prop="DEALER_SHORTNAME" label="代理商简称" min-width="50"/>
        </el-table>
        <!-- 分页 -->
        <Pagination :data="page" @change-size="handleSizeChange" @change-page="handleCurrentChange" />
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button type="primary" @click="req">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getUsersList,
  addUserInfo,
  getUserInfoById,
  editUserInfo,
  getDealerSelectList,
  getUsersListForExport
  // getDealerTableList
} from '@/api/admin/org/gms/employeeInfo'
import { restPassword } from '@/api/admin/auth/gms/user'
import { removeLockflag, lockflag } from '@/api/admin/auth/employeePermissionInfo'
import BaseTable from '@/components/BaseTable'
import rSelect from '@/components/Select/Select'
import Pagination from '@/components/Pagination'
import dealerSelect from './dealerSelect'
import formMixins from '@/mixins/formMixins'
import Gender from '@/components/Select/gender'
import IsOnjob from '@/components/Select/isOnjob'
import departmentSelect from '@/views/admin/org/gms/departmentSelect'
// import {
//   formatDate
// } from 'element-ui/packages/date-picker/src/util'
import _ from 'lodash'
import { phone, IDNumber, email, systemCode, zipCode } from '@/utils/validator'
import { exportFile } from '@/utils'
export default {
  name: 'GmsEmployeeInfo',
  components: {
    BaseTable,
    rSelect,
    Gender,
    IsOnjob,
    departmentSelect,
    dealerSelect,
    Pagination
  },
  // 过滤器
  filters: {
    isonjobFilter(val) {
      return val === 10081001 ? '在职' : '离职'
    },
    isYESORNO(val) {
      return val === 10041001 ? '是' : '否'
    },
    datasourcesFilter(val) {
      return val === 10451001 ? '店面' : '车厂'
    },
    genderFilter(val) {
      if (val === 10021001) {
        return '男'
      }
      if (val === 10021002) {
        return '女'
      }
      if (val === 10021003) {
        return '未知'
      }
    }
  },
  mixins: [formMixins],
  data() {
    return {
      active: 1,
      mode: ['1', '2'],
      way: '',
      text: '',
      bol: false,
      bols: true,
      load: false,
      dialogFormVisible: false,
      dialogVisible: false,
      multipleSelection: [],
      multipleSelection2: [],
      // 在职状态
      isOnjob: [{
        code: 10081001,
        name: '在职'
      },
      {
        code: 10081002,
        name: '离职'
      }
      ],
      rules: {
        EMPLOYEE_NO: [{
          required: true,
          message: '请填写员工编号',
          trigger: 'blur'
        },
        {
          trigger: 'blur', validator: systemCode
        }
        ],
        EMPLOYEE_NAME: [{
          required: true,
          message: '请填写员工姓名',
          trigger: 'blur'
        }],
        ORGANIZATION_NAME: [{
          required: true,
          message: '请选择部门',
          trigger: 'blur'
        }],
        IS_ONJOB: [{
          required: true,
          message: '请选择在职状态',
          trigger: 'blur'
        }],
        CERTIFICATE_ID: [{
          trigger: 'blur', validator: IDNumber
        }],
        E_MAIL: [{
          trigger: 'blur', validator: email
        }],
        ZIP_CODE: [{
          trigger: 'blur', validator: zipCode
        }],
        PHONE: [{
          required: true,
          message: '请填写手机',
          trigger: 'blur'
        },
        { trigger: 'blur', validator: phone }]
      },
      search: {
        limit: 10,
        pageNum: 1,
        employeeName: '',
        orgName: '',
        isOnjob: '',
        employeeNo: '',
        phone: '',
        userCode: '',
        departmentName: '',
        positionName: '',
        roleName: ''
      },
      dealerSearch: {
        limit: 10,
        pageNum: 1,
        dealerCode: '',
        dealerName: '',
        isDealer: 'yiji'
      },
      form: {
        EMPLOYEE_NO: '',
        EMPLOYEE_NAME: '',
        ORGANIZATION_NAME: '',
        ORGANIZATION_ID: '',
        EDUCATION: '',
        MOBILE: '',
        CERTIFICATE_ID: '',
        E_MAIL: '',
        ZIP_CODE: '',
        PHONE: '',
        BIRTHDAY: '',
        GENDER: '',
        WORKGROUP_CODE: '',
        DIMISSION_DATE: '',
        FOUND_DATE: '',
        ADDRESS: '',
        IS_ONJOB: '',
        BIG_RANGE: '',
        IS_FINANCIAL: 10041002,
        IS_PRINTER: 10041002,
        PRINT_ADDR: ''
      },
      checkedList: [],
      sites: [],
      key: '',
      tree: [],
      loading: false,
      positonCode: '',
      dealerDis: false,
      isST: true,
      dealerList: [],
      page: {},
      list: []
    }
  },
  computed: {},
  mounted() {
    this.searchHandle()
  },
  methods: {
    // 查询
    searchHandle() {
      const table = this.$refs['table']
      table.wait()
      getUsersList(this.search)
        .then(res => {
          table.complete().filData(res)
        })
        .catch(err => {
          table.complete()
        })
    },
    removelock(data) {
      this.$confirm('是否解锁', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          removeLockflag(data.EMP_ID).then(res => {
            this.$message({
              type: 'success',
              message: '解锁成功!'
            })
            this.searchHandle()
          })
            .catch(err => {
            })
        })
        .catch(err => {
          this.$message({
            type: 'info',
            message: '已取消解锁'
          })
        })
    },

    // 锁定
    lock(data) {
      this.$confirm('是否锁定', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          lockflag(data.EMP_ID).then(res => {
            this.$message({
              type: 'success',
              message: '锁定成功!'
            })
            this.searchHandle()
          })
            .catch(err => {
            })
        })
        .catch(err => {
          this.$message({
            type: 'info',
            message: '已取消锁定'
          })
        })
    },
    // 部门选择
    getDepartmentOrgTree(val) {
      this.form.ORGANIZATION_NAME = val.label
      this.form.ORGANIZATION_ID = val.id
    },
    // 代理商选择
    openDealer() {
      this.dialogVisible = true
      this.searchDealer()
    },
    searchDealer() {
      this.load = true
      getDealerSelectList(this.dealerSearch).then(res => {
        this.list = res.rows
        this.page = res
        this.load = false
      }).catch(err => {
        this.load = false
      })
    },
    // 代理商选择分页
    handleSizeChange(size) {
      this.dealerSearch.limit = size
      this.searchDealer()
    },
    handleCurrentChange(page) {
      this.dealerSearch.pageNum = page
      this.searchDealer()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleSelectionChange2(val) {
      this.multipleSelection2 = val
    },
    req() {
      const val = this.multipleSelection
      if (val.length === 0) {
        this.$message({
          type: 'info',
          message: '请选择数据!'
        })
        return false
      }
      const SelectListed = this.dealerList
      if (!SelectListed.length === 0) {
        for (let i = 0; i < SelectListed.length; i++) {
          for (let j = 0; j < val.length; j++) {
            if (SelectListed[i].DEALER_ID === val[j].DEALER_ID) {
              this.$message({
                type: 'info',
                message: '信息已存在，请重新选择!'
              })
              return
            }
          }
        }
      }
      this.dealerList = this.dealerList.concat(val)
      this.dealerSearch.dealerCode = ''
      this.dealerSearch.dealerName = ''
      this.dialogVisible = false
      this.$message({
        type: 'success',
        message: '添加成功!'
      })
      // this.searchHandle();
    },
    addDelete(index, row) {
      this.dealerList.splice(index, 1)
    },
    EmployeeRolesCheck(data) {
      this.$nextTick(() => {
        this.$refs.form.resetFields()
        this.form = {}
        this.checkedList = []
      })
      const id = data.EMP_ID
      getUserInfoById(id)
        .then(item => {
          // res.forEach(item => {
          const bigRangeString = item.BIG_RANGE
          if (bigRangeString != null && bigRangeString.length > 0) {
            const bigRangeArry = bigRangeString.split(',')
            const endArry = []
            for (var i = 0; i < bigRangeArry.length; i++) {
              endArry.push(Number(bigRangeArry[i]))
            }
            item.BIG_RANGE = endArry
          } else {
            item.BIG_RANGE = []
          }
          this.form = _.cloneDeep(item)
          // })
        })
        .catch(err => {
        })
        // getDealerTableList(id).then(res => {
        //   if(res[0].DEALER_ID!=null){
        //     this.dealerList = res;
        //    }
        // }).catch(err => {
        // });
    },
    // 打开编辑框
    edit(data) {
      this.text = '员工信息编辑'
      this.way = 'edit'
      this.bol = true
      this.bols = true
      this.dialogFormVisible = true
      this.EmployeeRolesCheck(data)
    },
    // 新增
    add() {
      this.text = '员工信息新增'
      this.way = 'add'
      this.bol = false
      this.bols = true
      this.$nextTick(() => {
        this.$refs.form.resetFields()
      })
      this.dialogFormVisible = true
      this.form.FOUND_DATE = new Date()
    },
    // 明细
    detail(data) {
      this.text = '员工信息明细'
      this.way = 'detail'
      this.bol = true
      this.bols = false
      this.dialogFormVisible = true
      this.EmployeeRolesCheck(data)
    },
    // 新增确认
    save() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          const userDealerList = this.dealerList
          userDealerList.forEach(item => {
            item['dealerId'] = item.DEALER_ID
          })
          const params = {
            isDealer: this.way,
            isST: this.isST,
            employeeNo: this.form.EMPLOYEE_NO,
            employeeName: this.form.EMPLOYEE_NAME,
            organizationId: this.form.ORGANIZATION_ID,
            organizationName: this.form.ORGANIZATION_NAME,
            education: this.form.EDUCATION,
            gender: this.form.GENDER,
            birthday: this.form.BIRTHDAY,
            certificateId: this.form.CERTIFICATE_ID,
            phone: this.form.PHONE,
            mobile: this.form.MOBILE,
            eMail: this.form.E_MAIL,
            zipCode: this.form.ZIP_CODE,
            isOnjob: this.form.IS_ONJOB,
            dimissionDate: this.form.DIMISSION_DATE,
            foundDate: this.form.FOUND_DATE,
            address: this.form.ADDRESS,
            defaultPosition: this.form.LABOUR_POSITION_CODE,
            bigRange: this.form.BIG_RANGE,
            userDealerList: userDealerList,
            isFinancial: this.form.IS_FINANCIAL,
            isPrinter: this.form.IS_PRINTER,
            printAddr: this.form.PRINT_ADDR
          }
          if (this.way === 'add') {
            addUserInfo(params).then(res => {
              this.$message({
                type: 'success',
                message: '员工信息保存成功!'
              })
              this.cancel()
              this.dialogFormVisible = false
              this.searchHandle()
            }).catch(err => {
              this.$message({
                type: 'error',
                message: err.response.data.errorMsg
              })
            })
          }
          if (this.way === 'edit') {
            editUserInfo(params, this.form.EMP_ID).then(res => {
              this.$message({
                type: 'success',
                message: '员工信息保存成功!'
              })
              this.cancel()
              this.dialogFormVisible = false
              this.searchHandle()
            }).catch(err => {
              this.$message({
                type: 'error',
                message: err.response.data.errorMsg
              })
            })
          }
        }
      })
    },
    cancel() {
      this.text = ''
      this.way = ''
      this.bol = false
      this.bols = true
      this.dialogFormVisible = false
      this.dealerList = []
    },
    // 在职状态改变事件
    isOnjobChange() {
      if (this.form.IS_ONJOB === 10081002) {
        this.form.DIMISSION_DATE = new Date()
      } else {
        this.form.DIMISSION_DATE = ''
      }
    },
    // 重置密码
    restClick() {
      if (this.multipleSelection2.length !== 0) {
        let empIds = ''
        this.multipleSelection2.forEach(item => {
          if (empIds === '') {
            empIds = item['EMP_ID']
          } else {
            empIds = empIds + ',' + item['EMP_ID']
          }
        })
        const param = {
          empIds: empIds,
          newPassword: '12345678'
        }
        restPassword(param)
          .then(() => {
            this.$message({
              type: 'success',
              message: '重置密码成功!'
            })
          }).catch(err => {

          })
      } else {
        this.$message({
          type: 'warning',
          message: '请选择表格数据'
        })
      }
    },
    exportData() {
      getUsersListForExport(this.search).then(res => {
        const option = {
          tHeader: ['员工账号', '员工编号', '员工姓名', '部门', '职位', '角色', '性别', '身份证号', '手机', '在职状态'],
          filterVal: ['USER_CODE', 'EMPLOYEE_NO', 'EMPLOYEE_NAME', 'ORGANIZATION_NAME', 'POSITION_NAME',
            'ROLE_NAME', 'GENDER_NAME', 'CERTIFICATE_ID', 'PHONE', 'IS_ONJOB_NAME'],
          table: res,
          fileName: '员工信息'
        }
        exportFile(option, () => {
        })
      }).catch(err => {})
    },
    handelRole(path) {
      this.$router.push(path)
    }
  }
}

</script>

<style scoped>
</style>
